Apple, the Apple logo, and Macintosh are registered trademarks of Apple Computer, Inc.
Mac and OpenDoc are trademarks of Apple Computer, Inc.
Changes since DR2
1) Fixed parameter passing errors with SetValue and GetValue.
ODByteArray
What is an ODByteArray?
An ODByteArray is defined as a sequence of octets:
typedef struct {
unsigned long _maximum;
unsigned long _length;
octet *_buffer;
} _IDL_SEQUENCE_octet;
typedef _IDL_SEQUENCE_octet ODByteArray;
_length is the number of bytes of relevant data.
_maximum is the number of bytes in the buffer.
_buffer is the pointer to the memory block containing the data.
Some rules about ODByteArray:
1) _length must be smaller or equal to _maximum.
2) kODNULL cannot be passed to any parameter which expects an ODByteArray pointer.
3) _buffer must be allocated by ODNewPtr or equivalent SOM functions.
Why do we need ODByteArray?
The original OpenDoc API accepted and returned buffer pointers and their corresponding sizes. However, the API has been updated to use ODByteArray. This renders the OpenDoc API CORBA compliant and ready for distribution.
Usage example:
The following examples creates ODByteArray on the stack. There is no restriction that ODByteArray is a stack variable. It can be allocated in the heap.
1) Setting a value on a storage unit with a pre-allocated buffer (ptr and size):
// Allocate the byte array on the stack
ODByteArray ba;
// Set up the byte array
ba._length = size;
ba._maximum = size;
ba._buffer = ptr;
// Get the value
su->SetValue(ev, &ba);
// ba will be deallocated automatically when the function exits.
// ptr needs to be explicitly deallocated by client.
2) Getting a value from a storage unit:
// Allocate the byte array on the stack. The fields are not pre-filled.